package com.lineage.data.npc.event;

import com.lineage.config.ConfigOther;
import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_Mazu extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_Mazu.class);
  
  private static final Map<Integer, String> _playList = new HashMap<>();
  
  public static NpcExecutor get() {
    return new Npc_Mazu();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (!pc.is_mazu()) {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "y_e_g_01"));
      } else {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "y_e_g_02"));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
    try {
      if (cmd.equalsIgnoreCase("0") && !pc.is_mazu()) {
        if (!pc.getInventory().checkItem(ConfigOther.monbossitem, ConfigOther.monbossitemcount)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("金币不足" + ConfigOther.monbossitemcount));
          return;
        } 
        if (pc.getQuest().get_step(9955) == 1) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("您今日妈祖已使用完毕，隔天再来找我吧。"));
          return;
        } 
        pc.getInventory().consumeItem(ConfigOther.monbossitem, ConfigOther.monbossitemcount);
        pc.set_mazu(true);
        pc.setSkillEffect(8591, ConfigOther.montime * 60 * 1000);
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 7321, 3600000));
        pc.set_mazu_time((ConfigOther.montime * 60 * 1000));
        pc.getQuest().set_step(9955, 1);
      } else {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("目前正在使用妈祖状态中"));
      } 
      pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
